home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Auge 4000 / Auge 4000 #64 (1992-08-13)(Amiga User Gruppe Einzugsgebiet 4000).zip / Auge 4000 #64 (1992-08-13)(Amiga User Gruppe Einzugsgebiet 4000).adf / TKEd / rexx / Format-Marked.tked < prev    next >
Text File  |  1992-06-12  |  2KB  |  74 lines

  1. /**
  2.  ** ARexx-program to format all lines of a marked text to a requested length 
  3.  **
  4.  ** Doesn't work perfectly in each case, but better than nothing
  5.  **  
  6.  ** © Tom Kroener '92
  7.  **
  8.  **/
  9.  
  10. options results
  11. address 'TKEd.1'                  /* Portname of the first started TKEd */
  12.  
  13. FirstMarkedLine                   /* Go to start */
  14. Start = result
  15. IF Start = -1 THEN                /* No block marked => EXIT */
  16.   DO;
  17.     Request1 "No lines marked!"
  18.     EXIT 10
  19.   END;
  20. GetLineNr                         /* Current line = last marked line +1*/
  21. End = result-1
  22. UnMarkBlock
  23. GetNumber "Enter length"          /* Length of a line after format */
  24. Length = result+1
  25. GotoLine Start
  26.  
  27. DO WHILE Start <= End             /* Format until it reaches the last line */
  28.   GetLineLen
  29.   IF result > 0 THEN              /* Skip blank lines */
  30.   DO;
  31.     DO WHILE result < Length      /* Line too short => join two lines */
  32.       Cursor "DOWN"
  33.       JoinLines
  34.       GetLineLen
  35.     END
  36.     GotoColumn (Length)           /* Goto end of the line */
  37.     PreviousWord                  /* Words won't be cuted */
  38.     Cursor "RIGHT"
  39.     MakeReturn                    /* Split the line */
  40.     Cursor "UP"                   /* Goto previous line */
  41.     BeginOfLine                   /* Goto beginning of the line */
  42.     GetChar
  43.     DO WHILE result = " "         /* Remove leading spaces */
  44.       Del
  45.       GetChar
  46.     END;
  47.     GetLineLen
  48.     DO WHILE result < Length      /* As long as the line is too short */
  49.       GetLineNr                   /* position in the text*/
  50.       YPos = result
  51.       NextWord                    /* 1 word left */
  52.       GetLineNr
  53.       IF result > YPos THEN       /* If NextWord jumps to the next line
  54.                                      => go to beginning */
  55.         DO;
  56.           BeginOfLine
  57.           Cursor "UP"
  58.         END;
  59.       WriteChar " "               /* Insert 1  blank */ 
  60.       GetLineLen
  61.     END;
  62.   END;
  63.   GetLineNr
  64.   Current = result
  65.   LastLine
  66.   IF result = Current THEN      /* End of text => EXIT */
  67.     EXIT 0
  68.   Start = Start + 1             /* Increment counter */
  69.   Cursor "DOWN"
  70. END;
  71.  
  72. EXIT 0
  73.  
  74.